package com.thinkgem.dingdan.test;

import java.io.FileOutputStream;
import java.util.Date;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class ExcelTestOne {

	public static void main(String[] args) {
		try {
			FileOutputStream fos = new FileOutputStream("G:\\dev_desk\\file\\15.xls");

			HSSFWorkbook wb = new HSSFWorkbook();

			/**
			 * ======================================================== 设置cell宽度
			 * 通过sheet 对象，setColumnWidth设置cell的宽度
			 * ========================================================
			 */

			// 设置默认宽度、高度值
			HSSFSheet sheet2 = wb.createSheet("sheet2");

			sheet2.setDefaultColumnWidth(10);
			sheet2.setDefaultRowHeightInPoints(25);
			// 格式化单元格日期信息
			HSSFDataFormat dataFormat = wb.createDataFormat();
			short dataformat = dataFormat.getFormat("yyyy-mm-dd HH:MM");
			HSSFCellStyle style = wb.createCellStyle();

			style.setDataFormat(dataformat);

			HSSFCell cell2 = sheet2.createRow(0).createCell(0);

			cell2.setCellValue(new Date());

			cell2.setCellStyle(style);

			wb.write(fos);

			fos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
